<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title> [[${pageTitle}]] - WMS仓库管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 160px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }

        .T-result {
            margin-bottom: 0;
        }

        .T-result em {
            color: #c33;
            font-style: normal;
        }
    </style>

    <!-- content starts -->
    <!--    <blockquote class="layui-elem-quote">待发货订单</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/order_delivery/wait_pick_order_list">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" placeholder="订单编号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="mjMobile" placeholder="收货人手机号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="shopId" id="shopId">
                                <option value="">店铺</option>
                                <option value="5" >东方概念旗舰店（拼多多）</option>
                                <option value="18" >华衣云购百货店（拼多多）</option>
                                <option value="99" >ERP系统</option>
                                <!--                                <option value="4">淘宝天猫</option>-->
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" id="startTime"
                                   placeholder="yyyy-MM-dd" autocomplete="off">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" id="endTime" placeholder="yyyy-MM-dd"
                                   autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</i>
                    </div>
                    <div class="layui-inline"></div>
<!--                    <div class="layui-inline">-->
<!--                        <a class="layui-btn layui-btn-normal" href="/order_delivery/order_return_djh_export" >导出</a>-->
<!--                    </div>-->

                </div>
            </form>


            <div class="layui-form-item">

                <div class="layui-inline" >
                    <a class="layui-btn layui-btn-normal" href="javascript:;" id="exportPrintOrder">生成拣货单(<span id="order-num">0</span>)</a>
                </div>
<!--                <div class="layui-inline">-->
<!--                    <a class="layui-btn layui-btn-normal" href="javascript:;" id="pickGoodsReview">生成拣货单(<span id="order-num_">0</span>)</a>-->
<!--                </div>-->

                <!--<div class="layui-inline">
                    <a class="layui-btn" href="javascript:;" id="cacelConfirmOrder">取消拣货</a>
                </div>-->

                <!--                <div class="layui-inline">-->
                <!--                    <form method="post" enctype="multipart/form-data" id="execl_form">-->
                <!--                        <input type="file" name="excel" id="excel" placeholder="已打印的菜鸟订单" class="layui-input">-->
                <!--                    </form>-->
                <!--                </div>-->

                <!--                <div class="layui-inline">-->
                <!--                    <button type="button" id="excel_upload_btn" class="layui-btn">导入物流信息（菜鸟已打印过的订单excel）</button>-->
                <!--                </div>-->
            </div>

        </div>
    </fieldset>

    <!--<div class="layui-inline"> <button class="layui-btn">批量发货</button></div>-->
    <!--<div class="layui-inline"> <a class="layui-btn" href="/order/printSendListOne">打印发货单模板1</a></div>-->
    <!--<div class="layui-inline"> <a class="layui-btn" href="/order/printSendListTwo">打印发货单模板2</a></div>-->

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/css/order.css"/>
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="dd-wrapper">

        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th><input id="allCheck" type="checkbox"/>订单ID</th>
                    <th>订单信息</th>
                    <th>店铺</th>
                    <th>商品</th>
                    <th>款号</th>
                    <th>sku</th>
                    <th>规格</th>
                    <th>数量</th>
                    <th>收件信息</th>
                    <th>备注信息</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <input id="orderIds" type="hidden" />
                <!--                <tr th:if="${totalSize == 0}">-->
                <!--                    <td colspan="11" align="center" style="vertical-align:middle; text-align:center;color: red;" ><h1>没有找到数据</h1></td>-->
                <!--                </tr>-->
                <tr th:each="item:${lists}">
                    <td >
                        <input th:if="${item.status == 0}" type="checkbox" class="ids currCheck" name="ids"
                               th:value="${item.id}"/>[[${item.id}]]
                    </td>
                    <td>
                        <p><b th:text="${item.order_num}"></b></p>
                        <p style="color: #9F9F9F;font-size: x-small">下单时间：<b th:text="${#dates.format(item.orderTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b>
                        <p style="color: #9F9F9F;font-size: x-small">确认时间：<b th:text="${#dates.format(item.confirmedTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b>
                        </p>
                    </td>
                    <td th:text="${item.shopName}"></td>
                    <td colspan="5">
                        <table>
                            <tr th:each="item1:${item.items}">
                                <td>
                                    <img th:src="${item1.colorImage}" style="width: 50px;height: 50px;">
                                </td>
                                <td th:text="${item1.productNumber}"></td>
                                <td th:text="${item1.skuNumber}"></td>
                                <td>
                                    <b th:text="${item1.colorValue}"></b>
                                    <b th:text="${item1.sizeValue}"></b>
                                </td>
                                <td th:text="${item1.quantity}"></td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <p>
                            <b th:text="${item.province}"></b>
                            <b th:text="${item.city}"></b>
                            <b th:text="${item.area}"></b>
                        </p>
                        <p>
                            <b th:text="${item.logisticsCompany}"></b><b th:text="${item.logisticsCode}"></b>
                        </p>
                    </td>
                    <td>
                        <span style="color: red" th:text="${item.remark}"></span>
                    </td>
                    <td><b th:text="${T(com.b2c.erp.enums.EnumErpOrderSendStatus).getName(item.status)}"></b></td>
                    <td>
                        <a class="cancel_order" th:if="${item.status == 0}" href="javascript:;" th:attr="data-id=${item.id}">取消订单</a>
                    </td>

                </tr>
                </tbody>
            </table>
            <div class="layui-box layui-laypage layui-laypage-default pageBox">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>



    </div>
    <!-- end dd-wrapper -->


<!--    <script type="text/template" id="send-goods">-->
<!--        <div class="T-box">-->
<!--            <p><span>快递公司</span>-->
<!--                <select id="send-company">-->
<!--                    <option value="">请选择快递公司</option>-->
<!--                    <option value="yunda">韵达快递</option>-->
<!--                </select>-->
<!--            </p>-->
<!--            <p><span>快递单号</span><input type="text" id="send-number"/></p>-->
<!--            <p><span>订单编号</span><i id="order-num"></i></p>-->
<!--            <p><span>下单时间</span><i id="order-time"></i></p>-->
<!--            <p><span>付款时间</span><i id="pay-time"></i></p>-->
<!--            <p class="T-result"><span>&nbsp;</span><em id="erro"></em></p>-->
<!--        </div>-->
<!--    </script>-->

    <script src="/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">
        layui.use(['laydate', 'layer','form'], function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
        });
        var r = /^\+?[1-9][0-9]*$/;
        $(function () {

            //弹出商品list
            $(".goods_list").click(function () {
                var id = $(this).attr("data-id");
                layer.open({
                    type: 2,
                    title: '订单商品列表',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/order/order_goods_list?id=' + id //iframe的url
                });
            })
            
            //加入拣货清单
            $("#pickGoodsReview").click(function () {
                var ids = [];
                    $("input[name^='ids']").each(function (i, el) {
                        if ($(this).is(':checked'))
                            ids.push($(this).val());
                    });
                    //console.log(ids);
                    if (ids.length == 0) {
                        alert("请选择订单");
                        return
                    }
                    else
                        $("#generating_picking").submit();
            })
            
           // (按订单生成拣货单)
            $("#exportPrintOrder").click(function () {
                var ids = [];
                $("input[name^='ids']").each(function (i, el) {
                    if ($(this).is(':checked'))
                        ids.push($(this).val());
                });
                //console.log(ids);
                if (ids.length == 0)
                    alert("请选择订单");
                else {
                    if (confirm("你选中的订单将会生成拣货单，确认要操作吗？")) {
                        $.ajax({
                            url: "/ajax_fahuo/generating_picking_list_by_order",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify({id: ids}),
                            success: function (res) {
                                console.log("加入拣货清单");
                                console.log(res);
                                if (res.code == 0) {
                                    alert("拣货单生成成功,拣货单ID：" + res.data);
                                    window.location.href = "/order_delivery/goods_picking_list?id="+res.data;
                                    // window.location.reload();
                                } else {
                                    alert(res.msg);
                                }
                            },
                            complete: function (XMLHttpRequest) {
                                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "NO_ACCESS") alert("无权限访问");
                            },
                        });
                    }
                }
            });

            //取消拣货单
            // $("#cacelConfirmOrder").click(function () {
            //     var ids = [];
            //     $("input[name^='ids']").each(function (i, el) {
            //         if ($(this).is(':checked'))
            //             ids.push($(this).val());
            //     });
            //     console.log(ids);
            //     if (ids.length == 0)
            //         alert("请选择订单");
            //     else {
            //         if (confirm("你选中的订单将会取消生成拣货单，确认要操作吗？")) {
            //             $.ajax({
            //                 url: "/ajax_order/cancel_order_confirm_picking",
            //                 type: "POST",
            //                 dataType: "json",
            //                 contentType: "application/json",
            //                 data: JSON.stringify({id: ids}),
            //                 success: function (res) {
            //                     if (res.code == 0) {
            //                         alert(res.msg);
            //                         location.reload(true);
            //                     } else {
            //                         alert(res.msg);
            //                     }
            //                 },
            //                 complete: function (XMLHttpRequest) {
            //                     if (XMLHttpRequest.getResponseHeader("REDIRECT") == "NO_ACCESS") alert("无权限访问");
            //                 },
            //             });
            //         }
            //     }
            // });

            //取消订单
            $(".cancel_order").click(function () {
                var ids = [];
                ids.push($(this).attr("data-id"));
                if (confirm("确定要取消订单吗？")) {
                    $.ajax({
                        url: "/ajax_order/cancel_order_confirm_picking",
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json",
                        data: JSON.stringify({id: ids}),
                        success: function (res) {
                            if (res.code == 0) {
                                alert(res.msg);
                                location.reload(true);
                            } else {
                                alert(res.msg);
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "NO_ACCESS") alert("无权限访问");
                        },
                    });
                }
            })


            //AJAX 上传菜鸟订单excel
            // $("#excel_upload_btn").click(function () {
            //     var excel = $("#excel").val();
            //     if (excel == '') {
            //         alert("请选择文件");
            //         return false;
            //     } else if (excel.lastIndexOf(".xls") < 0) {//可判断以.xls和.xlsx结尾的excel
            //         alert("只能上传Excel文件");
            //     } else if (excel.lastIndexOf(".xlsx") > 0) {
            //         alert("只能上传Excel文件");
            //     } else {
            //
            //
            //         var url = "/ajax_order/order_send_excel";
            //         var formData = new FormData($('#execl_form')[0]);
            //
            //         // var formData = new FormData();
            //         // formData.append("excel", document.getElementById("excel").files[0]);
            //         if (confirm("请确保你的excel是从菜鸟打印系统中导出的excel。你确定吗？")) {
            //
            //
            //             $.ajax({
            //                 url: url,
            //                 type: "post",
            //                 data: formData,
            //                 success: function (result) {
            //                     if (result.code == 0) {
            //                         alert("更新成功:" + result.data);
            //                         window.location.reload();
            //                     } else {
            //                         alert("更新失败:" + result.msg());
            //                     }
            //
            //                     // alert(JSON.stringify(result));
            //                     return false;
            //                 },
            //                 error: function () {
            //                     alert("excel上传失败");
            //                 },
            //                 cache: false,
            //                 contentType: false,
            //                 processData: false
            //             });
            //         }
            //     }
            //
            //     return false;
            // })

            $('#allCheck').on('change', function (e) {
                var checked = $('#allCheck').prop('checked');
                $('.currCheck').prop('checked', checked);
                $('#order-num').text(getNum());
                $('#order-num_').text(getNum());
            });

            $('.currCheck').on('change', function (e) {
                var allChecked;
                for (var i = 0; i < $('.currCheck').length; i++) {
                    var checked = $('.currCheck').eq(i).prop('checked');
                    if (!checked) {
                        $('#allCheck').prop('checked', false);
                        $('#order-num').text(getNum());
                        $('#order-num_').text(getNum());
                       return;
                    }
                }
                $('#allCheck').prop('checked', true);
                $('#order-num').text(getNum());
                $('#order-num_').text(getNum());
            });

            function getNum() {
                var num = 0;
                for (var i = 0; i < $('.currCheck').length; i++) {
                    var checked = $('.currCheck').eq(i).prop('checked');
                    if (checked) {
                        num++;
                    }
                }
                return num;
            }
        });
    </script>
</div>


</body>
<html>
